home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Freeware 1999 August
/
SGI Freeware 1999 August.iso
/
dist
/
fw_xemacs.idb
/
usr
/
freeware
/
lib
/
xemacs-20.4
/
info
/
lispref.info-18.z
/
lispref.info-18
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
Macintosh to JP
NeXTSTEP
RISC OS/Acorn
Shift JIS
UTF-8
Wrap
GNU Info File
|
1998-05-21
|
48.8 KB
|
1,211 lines
This is Info file ../../info/lispref.info, produced by Makeinfo version
1.68 from the input file lispref.texi.
Edition History:
GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
Programmer's Manual (for 19.13) Third Edition, July 1995 XEmacs Lisp
Reference Manual (for 19.14 and 20.0) v3.1, March 1996 XEmacs Lisp
Reference Manual (for 19.15 and 20.1, 20.2) v3.2, April, May 1997
Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
Foundation, Inc. Copyright (C) 1994, 1995 Sun Microsystems, Inc.
Copyright (C) 1995, 1996 Ben Wing.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided that the
entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions, except that this permission notice may be stated in a
translation approved by the Foundation.
Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided also
that the section entitled "GNU General Public License" is included
exactly as in the original, and provided that the entire resulting
derived work is distributed under the terms of a permission notice
identical to this one.
Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions, except that the section entitled "GNU General Public License"
may be included in a translation approved by the Free Software
Foundation instead of in the original English.
File: lispref.info, Node: Active Keymaps, Next: Key Lookup, Prev: Prefix Keys, Up: Keymaps
Active Keymaps
==============
XEmacs normally contains many keymaps; at any given time, just a few
of them are "active" in that they participate in the interpretation of
user input. These are the global keymap, the current buffer's local
keymap, and the keymaps of any enabled minor modes.
The "global keymap" holds the bindings of keys that are defined
regardless of the current buffer, such as `C-f'. The variable
`global-map' holds this keymap, which is always active.
Each buffer may have another keymap, its "local keymap", which may
contain new or overriding definitions for keys. The current buffer's
local keymap is always active except when `overriding-local-map' or
`overriding-terminal-local-map' overrides it. Extents and text
properties can specify an alternative local map for certain parts of the
buffer; see *Note Extents and Events::.
Each minor mode may have a keymap; if it does, the keymap is active
when the minor mode is enabled.
The variable `overriding-local-map' and
`overriding-terminal-local-map', if non-`nil', specify other local
keymaps that override the buffer's local map and all the minor mode
keymaps.
All the active keymaps are used together to determine what command to
execute when a key is entered. XEmacs searches these maps one by one,
in order of decreasing precedence, until it finds a binding in one of
the maps.
More specifically:
For key-presses, the order of keymaps searched is:
* the `keymap' property of any extent(s) or text properties at point;
* any applicable minor-mode maps;
* the current local map of the current buffer;
* the current global map.
For mouse-clicks, the order of keymaps searched is:
* the current local map of the `mouse-grabbed-buffer' if any;
* the `keymap' property of any extent(s) at the position of the click
(this includes modeline extents);
* the `modeline-map' of the buffer corresponding to the modeline
under the mouse (if the click happened over a modeline);
* the value of `toolbar-map' in the current buffer (if the click
happened over a toolbar);
* the current local map of the buffer under the mouse (does not
apply to toolbar clicks);
* any applicable minor-mode maps;
* the current global map.
Note that if `overriding-local-map' or
`overriding-terminal-local-map' is non-`nil', *only* those two maps and
the current global map are searched.
The procedure for searching a single keymap is called "key lookup";
see *Note Key Lookup::.
Since every buffer that uses the same major mode normally uses the
same local keymap, you can think of the keymap as local to the mode. A
change to the local keymap of a buffer (using `local-set-key', for
example) is seen also in the other buffers that share that keymap.
The local keymaps that are used for Lisp mode, C mode, and several
other major modes exist even if they have not yet been used. These
local maps are the values of the variables `lisp-mode-map',
`c-mode-map', and so on. For most other modes, which are less
frequently used, the local keymap is constructed only when the mode is
used for the first time in a session.
The minibuffer has local keymaps, too; they contain various
completion and exit commands. *Note Intro to Minibuffers::.
*Note Standard Keymaps::, for a list of standard keymaps.
- Function: current-keymaps &optional EVENT-OR-KEYS
This function returns a list of the current keymaps that will be
searched for bindings. This lists keymaps such as the current
local map and the minor-mode maps, but does not list the parents
of those keymaps. EVENT-OR-KEYS controls which keymaps will be
listed. If EVENT-OR-KEYS is a mouse event (or a vector whose last
element is a mouse event), the keymaps for that mouse event will
be listed. Otherwise, the keymaps for key presses will be listed.
- Variable: global-map
This variable contains the default global keymap that maps XEmacs
keyboard input to commands. The global keymap is normally this
keymap. The default global keymap is a full keymap that binds
`self-insert-command' to all of the printing characters.
It is normal practice to change the bindings in the global map,
but you should not assign this variable any value other than the
keymap it starts out with.
- Function: current-global-map
This function returns the current global keymap. This is the same
as the value of `global-map' unless you change one or the other.
(current-global-map)
=> #<keymap global-map 639 entries 0x221>
- Function: current-local-map
This function returns the current buffer's local keymap, or `nil'
if it has none. In the following example, the keymap for the
`*scratch*' buffer (using Lisp Interaction mode) has a number of
entries, including one prefix key, `C-x'.
(current-local-map)
=> #<keymap lisp-interaction-mode-map 5 entries 0x558>
(describe-bindings-internal (current-local-map))
=> ; Inserted into the buffer:
backspace backward-delete-char-untabify
linefeed eval-print-last-sexp
delete delete-char
C-j eval-print-last-sexp
C-x << Prefix Command >>
M-tab lisp-complete-symbol
M-; lisp-indent-for-comment
M-C-i lisp-complete-symbol
M-C-q indent-sexp
M-C-x eval-defun
Alt-backspace backward-kill-sexp
Alt-delete kill-sexp
C-x x edebug-defun
- Function: current-minor-mode-maps
This function returns a list of the keymaps of currently enabled
minor modes.
- Function: use-global-map KEYMAP
This function makes KEYMAP the new current global keymap. It
returns `nil'.
It is very unusual to change the global keymap.
- Function: use-local-map KEYMAP &optional BUFFER
This function makes KEYMAP the new local keymap of BUFFER. BUFFER
defaults to the current buffer. If KEYMAP is `nil', then the
buffer has no local keymap. `use-local-map' returns `nil'. Most
major mode commands use this function.
- Variable: minor-mode-map-alist
This variable is an alist describing keymaps that may or may not be
active according to the values of certain variables. Its elements
look like this:
(VARIABLE . KEYMAP)
The keymap KEYMAP is active whenever VARIABLE has a non-`nil'
value. Typically VARIABLE is the variable that enables or
disables a minor mode. *Note Keymaps and Minor Modes::.
Note that elements of `minor-mode-map-alist' do not have the same
structure as elements of `minor-mode-alist'. The map must be the
CDR of the element; a list with the map as the second element will
not do.
What's more, the keymap itself must appear in the CDR. It does not
work to store a variable in the CDR and make the map the value of
that variable.
When more than one minor mode keymap is active, their order of
priority is the order of `minor-mode-map-alist'. But you should
design minor modes so that they don't interfere with each other.
If you do this properly, the order will not matter.
See also `minor-mode-key-binding', above. See *Note Keymaps and
Minor Modes::, for more information about minor modes.
- Variable: modeline-map
This variable holds the keymap consulted for mouse-clicks on the
modeline of a window. This variable may be buffer-local; its
value will be looked up in the buffer of the window whose modeline
was clicked upon.
- Variable: toolbar-map
This variable holds the keymap consulted for mouse-clicks over a
toolbar.
- Variable: mouse-grabbed-buffer
If non-`nil', a buffer which should be consulted first for all
mouse activity. When a mouse-click is processed, it will first be
looked up in the local-map of this buffer, and then through the
normal mechanism if there is no binding for that click. This
buffer's value of `mode-motion-hook' will be consulted instead of
the `mode-motion-hook' of the buffer of the window under the mouse.
You should *bind* this, not set it.
- Variable: overriding-local-map
If non-`nil', this variable holds a keymap to use instead of the
buffer's local keymap and instead of all the minor mode keymaps.
This keymap, if any, overrides all other maps that would have been
active, except for the current global map.
- Variable: overriding-terminal-local-map
If non-`nil', this variable holds a keymap to use instead of the
buffer's local keymap and instead of all the minor mode keymaps,
but for the selected console only. (In other words, this variable
is always console-local; putting a keymap here only applies to
keystrokes coming from the selected console. *Note Consoles and
Devices::.) This keymap, if any, overrides all other maps that
would have been active, except for the current global map.
File: lispref.info, Node: Key Lookup, Next: Functions for Key Lookup, Prev: Active Keymaps, Up: Keymaps
Key Lookup
==========
"Key lookup" is the process of finding the binding of a key sequence
from a given keymap. Actual execution of the binding is not part of
key lookup.
Key lookup uses just the event type of each event in the key
sequence; the rest of the event is ignored. In fact, a key sequence
used for key lookup may designate mouse events with just their types
(symbols) instead of with entire mouse events (lists). *Note Events::.
Such a pseudo-key-sequence is insufficient for `command-execute', but
it is sufficient for looking up or rebinding a key.
When the key sequence consists of multiple events, key lookup
processes the events sequentially: the binding of the first event is
found, and must be a keymap; then the second event's binding is found in
that keymap, and so on until all the events in the key sequence are used
up. (The binding thus found for the last event may or may not be a
keymap.) Thus, the process of key lookup is defined in terms of a
simpler process for looking up a single event in a keymap. How that is
done depends on the type of object associated with the event in that
keymap.
Let's use the term "keymap entry" to describe the value found by
looking up an event type in a keymap. (This doesn't include the item
string and other extra elements in menu key bindings because
`lookup-key' and other key lookup functions don't include them in the
returned value.) While any Lisp object may be stored in a keymap as a
keymap entry, not all make sense for key lookup. Here is a list of the
meaningful kinds of keymap entries:
`nil'
`nil' means that the events used so far in the lookup form an
undefined key. When a keymap fails to mention an event type at
all, and has no default binding, that is equivalent to a binding
of `nil' for that event type.
KEYMAP
The events used so far in the lookup form a prefix key. The next
event of the key sequence is looked up in KEYMAP.
COMMAND
The events used so far in the lookup form a complete key, and
COMMAND is its binding. *Note What Is a Function::.
ARRAY
The array (either a string or a vector) is a keyboard macro. The
events used so far in the lookup form a complete key, and the
array is its binding. See *Note Keyboard Macros::, for more
information. (Note that you cannot use a shortened form of a key
sequence here, such as `(control y)'; you must use the full form
`[(control y)]'. *Note Key Sequences::.)
LIST
The meaning of a list depends on the types of the elements of the
list.
* If the CAR of LIST is `lambda', then the list is a lambda
expression. This is presumed to be a command, and is treated
as such (see above).
* If the CAR of LIST is a keymap and the CDR is an event type,
then this is an "indirect entry":
(OTHERMAP . OTHERTYPE)
When key lookup encounters an indirect entry, it looks up
instead the binding of OTHERTYPE in OTHERMAP and uses that.
This feature permits you to define one key as an alias for
another key. For example, an entry whose CAR is the keymap
called `esc-map' and whose CDR is 32 (the code for <SPC>)
means, "Use the global binding of `Meta-<SPC>', whatever that
may be."
SYMBOL
The function definition of SYMBOL is used in place of SYMBOL. If
that too is a symbol, then this process is repeated, any number of
times. Ultimately this should lead to an object that is a keymap,
a command or a keyboard macro. A list is allowed if it is a
keymap or a command, but indirect entries are not understood when
found via symbols.
Note that keymaps and keyboard macros (strings and vectors) are not
valid functions, so a symbol with a keymap, string, or vector as
its function definition is invalid as a function. It is, however,
valid as a key binding. If the definition is a keyboard macro,
then the symbol is also valid as an argument to `command-execute'
(*note Interactive Call::.).
The symbol `undefined' is worth special mention: it means to treat
the key as undefined. Strictly speaking, the key is defined, and
its binding is the command `undefined'; but that command does the
same thing that is done automatically for an undefined key: it
rings the bell (by calling `ding') but does not signal an error.
`undefined' is used in local keymaps to override a global key
binding and make the key "undefined" locally. A local binding of
`nil' would fail to do this because it would not override the
global binding.
ANYTHING ELSE
If any other type of object is found, the events used so far in the
lookup form a complete key, and the object is its binding, but the
binding is not executable as a command.
In short, a keymap entry may be a keymap, a command, a keyboard
macro, a symbol that leads to one of them, or an indirection or `nil'.
File: lispref.info, Node: Functions for Key Lookup, Next: Changing Key Bindings, Prev: Key Lookup, Up: Keymaps
Functions for Key Lookup
========================
Here are the functions and variables pertaining to key lookup.
- Function: lookup-key KEYMAP KEY &optional ACCEPT-DEFAULTS
This function returns the definition of KEY in KEYMAP. If the
string or vector KEY is not a valid key sequence according to the
prefix keys specified in KEYMAP (which means it is "too long" and
has extra events at the end), then the value is a number, the
number of events at the front of KEY that compose a complete key.
If ACCEPT-DEFAULTS is non-`nil', then `lookup-key' considers
default bindings as well as bindings for the specific events in
KEY. Otherwise, `lookup-key' reports only bindings for the
specific sequence KEY, ignoring default bindings except when you
explicitly ask about them.
All the other functions described in this chapter that look up
keys use `lookup-key'.
(lookup-key (current-global-map) "\C-x\C-f")
=> find-file
(lookup-key (current-global-map) "\C-x\C-f12345")
=> 2
If KEY begins with the character whose value is contained in
`meta-prefix-char', that character is implicitly removed and the
<META> modifier added to the key. Thus, the first example below is
handled by conversion into the second example.
(lookup-key (current-global-map) "\ef")
=> forward-word
(lookup-key (current-global-map) "\M-f")
=> forward-word
Unlike `read-key-sequence', this function does not modify the
specified events in ways that discard information (*note Key
Sequence Input::.). In particular, it does not convert letters to
lower case.
- Command: undefined
Used in keymaps to undefine keys. If a key sequence is defined to
this, invoking this key sequence causes a "key undefined" error,
just as if the key sequence had no binding.
- Function: key-binding KEY &optional ACCEPT-DEFAULTS
This function returns the binding for KEY in the current keymaps,
trying all the active keymaps. The result is `nil' if KEY is
undefined in the keymaps.
The argument ACCEPT-DEFAULTS controls checking for default
bindings, as in `lookup-key' (above).
(key-binding "\C-x\C-f")
=> find-file
(key-binding '(control home))
=> beginning-of-buffer
(key-binding [escape escape escape])
=> keyboard-escape-quit
- Function: local-key-binding KEY &optional ACCEPT-DEFAULTS
This function returns the binding for KEY in the current local
keymap, or `nil' if it is undefined there.
The argument ACCEPT-DEFAULTS controls checking for default
bindings, as in `lookup-key' (above).
- Function: global-key-binding KEY &optional ACCEPT-DEFAULTS
This function returns the binding for command KEY in the current
global keymap, or `nil' if it is undefined there.
The argument ACCEPT-DEFAULTS controls checking for default
bindings, as in `lookup-key' (above).
- Function: minor-mode-key-binding KEY &optional ACCEPT-DEFAULTS
This function returns a list of all the active minor mode bindings
of KEY. More precisely, it returns an alist of pairs `(MODENAME .
BINDING)', where MODENAME is the variable that enables the minor
mode, and BINDING is KEY's binding in that mode. If KEY has no
minor-mode bindings, the value is `nil'.
If the first binding is not a prefix command, all subsequent
bindings from other minor modes are omitted, since they would be
completely shadowed. Similarly, the list omits non-prefix
bindings that follow prefix bindings.
The argument ACCEPT-DEFAULTS controls checking for default
bindings, as in `lookup-key' (above).
- Variable: meta-prefix-char
This variable is the meta-prefix character code. It is used when
translating a two-character sequence to a meta character so it can
be looked up in a keymap. For useful results, the value should be
a prefix event (*note Prefix Keys::.). The default value is
`?\^[' (integer 27), which is the ASCII character usually produced
by the <ESC> key.
As long as the value of `meta-prefix-char' remains `?\^[', key
lookup translates `<ESC> b' into `M-b', which is normally defined
as the `backward-word' command. However, if you set
`meta-prefix-char' to `?\^X' (i.e. the keystroke `C-x') or its
equivalent ASCII code `24', then XEmacs will translate `C-x b'
(whose standard binding is the `switch-to-buffer' command) into
`M-b'.
meta-prefix-char ; The default value.
=> ?\^[ ; Under XEmacs 20.
=> 27 ; Under XEmacs 19.
(key-binding "\eb")
=> backward-word
?\C-x ; The print representation
; of a character.
=> ?\^X ; Under XEmacs 20.
=> 24 ; Under XEmacs 19.
(setq meta-prefix-char 24)
=> 24
(key-binding "\C-xb")
=> backward-word ; Now, typing `C-x b' is
; like typing `M-b'.
(setq meta-prefix-char ?\e) ; Avoid confusion!
; Restore the default value!
=> ?\^[ ; Under XEmacs 20.
=> 27 ; Under XEmacs 19.
File: lispref.info, Node: Changing Key Bindings, Next: Key Binding Commands, Prev: Functions for Key Lookup, Up: Keymaps
Changing Key Bindings
=====================
The way to rebind a key is to change its entry in a keymap. If you
change a binding in the global keymap, the change is effective in all
buffers (though it has no direct effect in buffers that shadow the
global binding with a local one). If you change the current buffer's
local map, that usually affects all buffers using the same major mode.
The `global-set-key' and `local-set-key' functions are convenient
interfaces for these operations (*note Key Binding Commands::.). You
can also use `define-key', a more general function; then you must
specify explicitly the map to change.
The way to specify the key sequence that you want to rebind is
described above (*note Key Sequences::.).
For the functions below, an error is signaled if KEYMAP is not a
keymap or if KEY is not a string or vector representing a key sequence.
You can use event types (symbols) as shorthand for events that are
lists.
- Function: define-key KEYMAP KEY BINDING
This function sets the binding for KEY in KEYMAP. (If KEY is more
than one event long, the change is actually made in another keymap
reached from KEYMAP.) The argument BINDING can be any Lisp
object, but only certain types are meaningful. (For a list of
meaningful types, see *Note Key Lookup::.) The value returned by
`define-key' is BINDING.
Every prefix of KEY must be a prefix key (i.e., bound to a keymap)
or undefined; otherwise an error is signaled.
If some prefix of KEY is undefined, then `define-key' defines it
as a prefix key so that the rest of KEY may be defined as
specified.
Here is an example that creates a sparse keymap and makes a number of
bindings in it:
(setq map (make-sparse-keymap))
=> #<keymap 0 entries 0xbee>
(define-key map "\C-f" 'forward-char)
=> forward-char
map
=> #<keymap 1 entry 0xbee>
(describe-bindings-internal map)
=> ; (Inserted in buffer)
C-f forward-char
;; Build sparse submap for `C-x' and bind `f' in that.
(define-key map "\C-xf" 'forward-word)
=> forward-word
map
=> #<keymap 2 entries 0xbee>
(describe-bindings-internal map)
=> ; (Inserted in buffer)
C-f forward-char
C-x << Prefix Command >>
C-x f forward-word
;; Bind `C-p' to the `ctl-x-map'.
(define-key map "\C-p" ctl-x-map)
;; `ctl-x-map'
=> #<keymap Control-X-prefix 77 entries 0x3bf>
;; Bind `C-f' to `foo' in the `ctl-x-map'.
(define-key map "\C-p\C-f" 'foo)
=> foo
map
=> #<keymap 3 entries 0xbee>
(describe-bindings-internal map)
=> ; (Inserted in buffer)
C-f forward-char
C-p << Prefix command Control-X-prefix >>
C-x << Prefix Command >>
C-p tab indent-rigidly
C-p $ set-selective-display
C-p ' expand-abbrev
C-p ( start-kbd-macro
C-p ) end-kbd-macro
...
C-p C-x exchange-point-and-mark
C-p C-z suspend-or-iconify-emacs
C-p M-escape repeat-complex-command
C-p M-C-[ repeat-complex-command
C-x f forward-word
C-p 4 . find-tag-other-window
...
C-p 4 C-o display-buffer
C-p 5 0 delete-frame
...
C-p 5 C-f find-file-other-frame
...
C-p a i g inverse-add-global-abbrev
C-p a i l inverse-add-mode-abbrev
Note that storing a new binding for `C-p C-f' actually works by
changing an entry in `ctl-x-map', and this has the effect of changing
the bindings of both `C-p C-f' and `C-x C-f' in the default global map.
- Function: substitute-key-definition OLDDEF NEWDEF KEYMAP &optional
OLDMAP
This function replaces OLDDEF with NEWDEF for any keys in KEYMAP
that were bound to OLDDEF. In other words, OLDDEF is replaced
with NEWDEF wherever it appears. The function returns `nil'.
For example, this redefines `C-x C-f', if you do it in an XEmacs
with standard bindings:
(substitute-key-definition
'find-file 'find-file-read-only (current-global-map))
If OLDMAP is non-`nil', then its bindings determine which keys to
rebind. The rebindings still happen in NEWMAP, not in OLDMAP.
Thus, you can change one map under the control of the bindings in
another. For example,
(substitute-key-definition
'delete-backward-char 'my-funny-delete
my-map global-map)
puts the special deletion command in `my-map' for whichever keys
are globally bound to the standard deletion command.
- Function: suppress-keymap KEYMAP &optional NODIGITS
This function changes the contents of the full keymap KEYMAP by
making all the printing characters undefined. More precisely, it
binds them to the command `undefined'. This makes ordinary
insertion of text impossible. `suppress-keymap' returns `nil'.
If NODIGITS is `nil', then `suppress-keymap' defines digits to run
`digit-argument', and `-' to run `negative-argument'. Otherwise
it makes them undefined like the rest of the printing characters.
The `suppress-keymap' function does not make it impossible to
modify a buffer, as it does not suppress commands such as `yank'
and `quoted-insert'. To prevent any modification of a buffer, make
it read-only (*note Read Only Buffers::.).
Since this function modifies KEYMAP, you would normally use it on
a newly created keymap. Operating on an existing keymap that is
used for some other purpose is likely to cause trouble; for
example, suppressing `global-map' would make it impossible to use
most of XEmacs.
Most often, `suppress-keymap' is used to initialize local keymaps
of modes such as Rmail and Dired where insertion of text is not
desirable and the buffer is read-only. Here is an example taken
from the file `emacs/lisp/dired.el', showing how the local keymap
for Dired mode is set up:
...
(setq dired-mode-map (make-keymap))
(suppress-keymap dired-mode-map)
(define-key dired-mode-map "r" 'dired-rename-file)
(define-key dired-mode-map "\C-d" 'dired-flag-file-deleted)
(define-key dired-mode-map "d" 'dired-flag-file-deleted)
(define-key dired-mode-map "v" 'dired-view-file)
(define-key dired-mode-map "e" 'dired-find-file)
(define-key dired-mode-map "f" 'dired-find-file)
...
File: lispref.info, Node: Key Binding Commands, Next: Scanning Keymaps, Prev: Changing Key Bindings, Up: Keymaps
Commands for Binding Keys
=========================
This section describes some convenient interactive interfaces for
changing key bindings. They work by calling `define-key'.
People often use `global-set-key' in their `.emacs' file for simple
customization. For example,
(global-set-key "\C-x\C-\\" 'next-line)
or
(global-set-key [(control ?x) (control ?\\)] 'next-line)
or
(global-set-key [?\C-x ?\C-\\] 'next-line)
redefines `C-x C-\' to move down a line.
(global-set-key [(meta button1)] 'mouse-set-point)
redefines the first (leftmost) mouse button, typed with the Meta key, to
set point where you click.
- Command: global-set-key KEY DEFINITION
This function sets the binding of KEY in the current global map to
DEFINITION.
(global-set-key KEY DEFINITION)
==
(define-key (current-global-map) KEY DEFINITION)
- Command: global-unset-key KEY
This function removes the binding of KEY from the current global
map.
One use of this function is in preparation for defining a longer
key that uses KEY as a prefix--which would not be allowed if KEY
has a non-prefix binding. For example:
(global-unset-key "\C-l")
=> nil
(global-set-key "\C-l\C-l" 'redraw-display)
=> nil
This function is implemented simply using `define-key':
(global-unset-key KEY)
==
(define-key (current-global-map) KEY nil)
- Command: local-set-key KEY DEFINITION
This function sets the binding of KEY in the current local keymap
to DEFINITION.
(local-set-key KEY DEFINITION)
==
(define-key (current-local-map) KEY DEFINITION)
- Command: local-unset-key KEY
This function removes the binding of KEY from the current local
map.
(local-unset-key KEY)
==
(define-key (current-local-map) KEY nil)
File: lispref.info, Node: Scanning Keymaps, Next: Other Keymap Functions, Prev: Key Binding Commands, Up: Keymaps
Scanning Keymaps
================
This section describes functions used to scan all the current
keymaps, or all keys within a keymap, for the sake of printing help
information.
- Function: accessible-keymaps KEYMAP &optional PREFIX
This function returns a list of all the keymaps that can be
accessed (via prefix keys) from KEYMAP. The value is an
association list with elements of the form `(KEY . MAP)', where
KEY is a prefix key whose definition in KEYMAP is MAP.
The elements of the alist are ordered so that the KEY increases in
length. The first element is always `([] . KEYMAP)', because the
specified keymap is accessible from itself with a prefix of no
events.
If PREFIX is given, it should be a prefix key sequence; then
`accessible-keymaps' includes only the submaps whose prefixes start
with PREFIX. These elements look just as they do in the value of
`(accessible-keymaps)'; the only difference is that some elements
are omitted.
In the example below, the returned alist indicates that the key
`C-x', which is displayed as `[(control x)]', is a prefix key
whose definition is the keymap `#<keymap ((control x) #<keymap
emacs-lisp-mode-map 8 entries 0x546>) 1 entry 0x8a2>'. (The strange
notation for the keymap's name indicates that this is an internal
submap of `emacs-lisp-mode-map'. This is because
`lisp-interaction-mode-map' has set up `emacs-lisp-mode-map' as
its parent, and `lisp-interaction-mode-map' defines no key
sequences beginning with `C-x'.)
(current-local-map)
=> #<keymap lisp-interaction-mode-map 5 entries 0x558>
(accessible-keymaps (current-local-map))
=>(([] . #<keymap lisp-interaction-mode-map 5 entries 0x558>)
([(control x)] .
#<keymap ((control x) #<keymap emacs-lisp-mode-map 8 entries 0x546>)
1 entry 0x8a2>))
The following example shows the results of calling
`accessible-keymaps' on a large, complex keymap. Notice how some
keymaps were given explicit names using `set-keymap-name'; those
submaps without explicit names are given descriptive names
indicating their relationship to their enclosing keymap.
(accessible-keymaps (current-global-map))
=> (([] . #<keymap global-map 639 entries 0x221>)
([(control c)] . #<keymap mode-specific-command-prefix 1 entry 0x3cb>)
([(control h)] . #<keymap help-map 33 entries 0x4ec>)
([(control x)] . #<keymap Control-X-prefix 77 entries 0x3bf>)
([(meta escape)] .
#<keymap ((meta escape) #<keymap global-map 639 entries 0x221>)
3 entries 0x3e0>)
([(meta control \[)] .
#<keymap ((meta escape) #<keymap global-map 639 entries 0x221>)
3 entries 0x3e0>)
([f1] . #<keymap help-map 33 entries 0x4ec>)
([(control x) \4] . #<keymap ctl-x-4-prefix 9 entries 0x3c5>)
([(control x) \5] . #<keymap ctl-x-5-prefix 8 entries 0x3c8>)
([(control x) \6] . #<keymap 13 entries 0x4d2>)
([(control x) a] .
#<keymap (a #<keymap Control-X-prefix 77 entries 0x3bf>)
8 entries 0x3ef>)
([(control x) n] . #<keymap narrowing-prefix 3 entries 0x3dd>)
([(control x) r] . #<keymap rectangle-prefix 18 entries 0x3e9>)
([(control x) v] . #<keymap vc-prefix-map 13 entries 0x60e>)
([(control x) a i] .
#<keymap (i #<keymap (a #<keymap Control-X-prefix 77 entries 0x3bf>)
8 entries 0x3ef>)
2 entries 0x3f5>))
- Function: map-keymap FUNCTION KEYMAP &optional SORT-FIRST
This function applies FUNCTION to each element of `KEYMAP'.
FUNCTION will be called with two arguments: a key-description
list, and the binding. The order in which the elements of the
keymap are passed to the function is unspecified. If the function
inserts new elements into the keymap, it may or may not be called
with them later. No element of the keymap will ever be passed to
the function more than once.
The function will not be called on elements of this keymap's
parents (*note Inheritance and Keymaps::.) or upon keymaps which
are contained within this keymap (multi-character definitions).
It will be called on <META> characters since they are not really
two-character sequences.
If the optional third argument SORT-FIRST is non-`nil', then the
elements of the keymap will be passed to the mapper function in a
canonical order. Otherwise, they will be passed in hash (that is,
random) order, which is faster.
- Function: keymap-fullness KEYMAP
This function returns the number of bindings in the keymap.
- Function: where-is-internal DEFINITION &optional KEYMAPS FIRSTONLY
NOINDIRECT EVENT-OR-KEYS
This function returns a list of key sequences (of any length) that
are bound to DEFINITION in a set of keymaps.
The argument DEFINITION can be any object; it is compared with all
keymap entries using `eq'.
KEYMAPS can be either a keymap (meaning search in that keymap and
the current global keymap) or a list of keymaps (meaning search in
exactly those keymaps and no others). If KEYMAPS is nil, search
in the currently applicable maps for EVENT-OR-KEYS.
If KEYMAP is a keymap, then the maps searched are KEYMAP and the
global keymap. If KEYMAP is a list of keymaps, then the maps
searched are exactly those keymaps, and no others. If KEYMAP is
`nil', then the maps used are the current active keymaps for
EVENT-OR-KEYS (this is equivalent to specifying `(current-keymaps
EVENT-OR-KEYS)' as the argument to KEYMAPS).
If FIRSTONLY is non-`nil', then the value is a single vector
representing the first key sequence found, rather than a list of
all possible key sequences.
If NOINDIRECT is non-`nil', `where-is-internal' doesn't follow
indirect keymap bindings. This makes it possible to search for an
indirect definition itself.
This function is used by `where-is' (*note Help: (emacs)Help.).
(where-is-internal 'describe-function)
=> ([(control h) d] [(control h) f] [f1 d] [f1 f])
- Function: describe-bindings-internal MAP &optional ALL SHADOW PREFIX
MOUSE-ONLY-P
This function inserts (into the current buffer) a list of all
defined keys and their definitions in MAP. Optional second
argument ALL says whether to include even "uninteresting"
definitions, i.e. symbols with a non-`nil' `suppress-keymap'
property. Third argument SHADOW is a list of keymaps whose
bindings shadow those of map; if a binding is present in any
shadowing map, it is not printed. Fourth argument PREFIX, if
non-`nil', should be a key sequence; only bindings which start
with that key sequence will be printed. Fifth argument
MOUSE-ONLY-P says to only print bindings for mouse clicks.
`describe-bindings-internal' is used to implement the help command
`describe-bindings'.
- Command: describe-bindings PREFIX MOUSE-ONLY-P
This function creates a listing of all defined keys and their
definitions. It writes the listing in a buffer named `*Help*' and
displays it in a window.
If PREFIX is non-`nil', it should be a prefix key; then the
listing includes only keys that start with PREFIX.
When several characters with consecutive ASCII codes have the same
definition, they are shown together, as `FIRSTCHAR..LASTCHAR'. In
this instance, you need to know the ASCII codes to understand
which characters this means. For example, in the default global
map, the characters `<SPC> .. ~' are described by a single line.
<SPC> is ASCII 32, `~' is ASCII 126, and the characters between
them include all the normal printing characters, (e.g., letters,
digits, punctuation, etc.); all these characters are bound to
`self-insert-command'.
If the second argument (prefix arg, interactively) is non-`nil'
then only the mouse bindings are displayed.
File: lispref.info, Node: Other Keymap Functions, Prev: Scanning Keymaps, Up: Keymaps
Other Keymap Functions
======================
- Function: set-keymap-prompt KEYMAP NEW-PROMPT
This function sets the "prompt" of KEYMAP to string NEW-PROMPT, or
`nil' if no prompt is desired. The prompt is shown in the
echo-area when reading a key-sequence to be looked-up in this
keymap.
- Function: keymap-prompt KEYMAP &optional USE-INHERITED
This function returns the "prompt" of the given keymap. If
USE-INHERITED is non-`nil', any parent keymaps will also be
searched for a prompt.
File: lispref.info, Node: Menus, Next: Dialog Boxes, Prev: Keymaps, Up: Top
Menus
*****
* Menu:
* Menu Format:: Format of a menu description.
* Menubar Format:: How to specify a menubar.
* Menubar:: Functions for controlling the menubar.
* Modifying Menus:: Modifying a menu description.
* Pop-Up Menus:: Functions for specifying pop-up menus.
* Menu Filters:: Filter functions for the default menubar.
* Menu Accelerators:: Using and controlling menu accelerator keys
* Buffers Menu:: The menu that displays the list of buffers.
File: lispref.info, Node: Menu Format, Next: Menubar Format, Up: Menus
Format of Menus
===============
A menu is described using a "menu description", which is a list of
menu items, keyword-value pairs, strings, and submenus. The menu
description specifies which items are present in the menu, what function
each item invokes, and whether the item is selectable or not. Pop-up
menus are directly described with a menu description, while menubars are
described slightly differently (see below).
The first element of a menu must be a string, which is the name of
the menu. This is the string that will be displayed in the parent menu
or menubar, if any. This string is not displayed in the menu itself,
except in the case of the top level pop-up menu, where there is no
parent. In this case, the string will be displayed at the top of the
menu if `popup-menu-titles' is non-`nil'.
Immediately following the first element there may optionally be up
to four keyword-value pairs, as follows:
`:included FORM'
This can be used to control the visibility of a menu. The form is
evaluated and the menu will be omitted if the result is `nil'.
`:config SYMBOL'
This is an efficient shorthand for `:included (memq SYMBOL
menubar-configuration)'. See the variable `menubar-configuration'.
`:filter FUNCTION'
A menu filter is used to sensitize or incrementally create a
submenu only when it is selected by the user and not every time
the menubar is activated. The filter function is passed the list
of menu items in the submenu and must return a list of menu items
to be used for the menu. It is called only when the menu is about
to be displayed, so other menus may already be displayed. Vile
and terrible things will happen if a menu filter function changes
the current buffer, window, or frame. It also should not raise,
lower, or iconify any frames. Basically, the filter function
should have no side-effects.
`:accelerator KEY'
A menu accelerator is a keystroke which can be pressed while the
menu is visible which will immediately activate the item. KEY
must be a char or the symbol name of a key. *Note Menu
Accelerators::.
The rest of the menu consists of elements as follows:
* A "menu item", which is a vector in the following form:
`[ NAME CALLBACK :KEYWORD VALUE :KEYWORD VALUE ... ]'
NAME is a string, the name of the menu item; it is the string to
display on the menu. It is filtered through the resource
database, so it is possible for resources to override what string
is actually displayed.
CALLBACK is a form that will be invoked when the menu item is
selected. If the callback of a menu item is a symbol, then it
must name a command. It will be invoked with
`call-interactively'. If it is a list, then it is evaluated with
`eval'.
The valid keywords and their meanings are described below.
Note that for compatibility purposes, the form
`[ NAME CALLBACK ACTIVE-P ]'
is also accepted and is equivalent to
`[ NAME CALLBACK :active ACTIVE-P ]'
and the form
`[ NAME CALLBACK ACTIVE-P SUFFIX]'
is accepted and is equivalent to
`[ NAME CALLBACK :active ACTIVE-P :suffix SUFFIX]'
However, these older forms are deprecated and should generally not
be used.
* If an element of a menu is a string, then that string will be
presented in the menu as unselectable text.
* If an element of a menu is a string consisting solely of hyphens,
then that item will be presented as a solid horizontal line.
* If an element of a menu is a string beginning with `--:', then a
particular sort of horizontal line will be displayed, as follows:
`"--:singleLine"'
A solid horizontal line. This is equivalent to a string
consisting solely of hyphens.
`"--:doubleLine"'
A solid double horizontal line.
`"--:singleDashedLine"'
A dashed horizontal line.
`"--:doubleDashedLine"'
A dashed double horizontal line.
`"--:noLine"'
No line (but a small space is left).
`"--:shadowEtchedIn"'
A solid horizontal line with a 3-d recessed appearance.
`"--:shadowEtchedOut"'
A solid horizontal line with a 3-d pushed-out appearance.
`"--:shadowDoubleEtchedIn"'
A solid double horizontal line with a 3-d recessed appearance.
`"--:shadowDoubleEtchedOut"'
A solid double horizontal line with a 3-d pushed-out
appearance.
`"--:shadowEtchedInDash"'
A dashed horizontal line with a 3-d recessed appearance.
`"--:shadowEtchedOutDash"'
A dashed horizontal line with a 3-d pushed-out appearance.
`"--:shadowDoubleEtchedInDash"'
A dashed double horizontal line with a 3-d recessed
appearance.
`"--:shadowDoubleEtchedOutDash"'
A dashed double horizontal line with a 3-d pushed-out
appearance.
* If an element of a menu is a list, it is treated as a submenu.
The name of that submenu (the first element in the list) will be
used as the name of the item representing this menu on the parent.
The possible keywords are as follows:
:active FORM
FORM will be evaluated when the menu that this item is a part of
is about to be displayed, and the item will be selectable only if
the result is non-`nil'. If the item is unselectable, it will
usually be displayed grayed-out to indicate this.
:suffix STRING
The string is appended to the displayed name. This provides a
convenient way of adding the name of a command's "argument" to the
menu, like `Kill Buffer NAME'.
:keys STRING
Normally, the keyboard equivalents of commands in menus are
displayed when the "callback" is a symbol. This can be used to
specify keys for more complex menu items. It is passed through
`substitute-command-keys' first.
:style STYLE
Specifies what kind of object this menu item is. STYLE be one of
the symbols
`nil'
A normal menu item.
`toggle'
A toggle button.
`radio'
A radio button.
`button'
A menubar button.
The only difference between toggle and radio buttons is how they
are displayed. But for consistency, a toggle button should be
used when there is one option whose value can be turned on or off,
and radio buttons should be used when there is a set of mutually
exclusive options. When using a group of radio buttons, you
should arrange for no more than one to be marked as selected at a
time.
:selected FORM
Meaningful only when STYLE is `toggle', `radio' or `button'. This
specifies whether the button will be in the selected or unselected
state. FORM is evaluated, as for `:active'.
:included FORM
This can be used to control the visibility of a menu item. The
form is evaluated and the menu item is only displayed if the
result is non-`nil'. Note that this is different from `:active':
If `:active' evaluates to `nil', the item will be displayed grayed
out, while if `:included' evaluates to `nil', the item will be
omitted entirely.
:config SYMBOL
This is an efficient shorthand for `:included (memq SYMBOL
menubar-configuration)'. See the variable `menubar-configuration'.
:accelerator KEY
A menu accelerator is a keystroke which can be pressed while the
menu is visible which will immediately activate the item. KEY
must be a char or the symbol name of a key. *Note Menu
Accelerators::.
- Variable: menubar-configuration
This variable holds a list of symbols, against which the value of
the `:config' tag for each menubar item will be compared. If a
menubar item has a `:config' tag, then it is omitted from the
menubar if that tag is not a member of the `menubar-configuration'
list.
For example:
("File"
:filter file-menu-filter ; file-menu-filter is a function that takes
; one argument (a list of menu items) and
; returns a list of menu items
[ "Save As..." write-file t ]
[ "Revert Buffer" revert-buffer (buffer-modified-p) ]
[ "Read Only" toggle-read-only :style toggle :selected buffer-read-only ]
)
File: lispref.info, Node: Menubar Format, Next: Menubar, Prev: Menu Format, Up: Menus
Format of the Menubar
=====================
A menubar is a list of menus, menu items, and strings. The format is
similar to that of a menu, except:
* The first item need not be a string, and is not treated specially.
* A string consisting solely of hyphens is not treated specially.
* If an element of a menubar is `nil', then it is used to represent
the division between the set of menubar items which are flush-left
and those which are flush-right. (Note: this isn't completely
implemented yet.)